package com.zhiwang.planet.ui.main

import android.os.Bundle
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import android.webkit.JavascriptInterface
import androidx.appcompat.app.AppCompatActivity
import com.zhiwang.planet.R
import com.zhiwang.planet.di.component.DaggerUserComponent
import com.zhiwang.planet.di.module.AccountModule
import com.zhiwang.planet.di.module.AutoDisposeModule
import com.zhiwang.planet.event.PlayAdVideoEvent
import com.zhiwang.planet.event.TabChangeEvent
import com.zhiwang.planet.mvp.p.UserPresenter
import com.zhiwang.planet.ui.WebViewFragment
import com.zhiwang.planet.widget.SimpleDialogBuilder
import org.greenrobot.eventbus.EventBus
import javax.inject.Inject

class GuideFragment : WebViewFragment() {


    companion object {
        fun newInstance(url: String): GuideFragment {
            val args = Bundle()

            val fragment = GuideFragment()
            fragment.url = url;
            fragment.arguments = args
            return fragment
        }
    }


    @Inject
    lateinit var userPresenter:UserPresenter

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        DaggerUserComponent.builder()
                .accountModule(AccountModule(requireActivity() as AppCompatActivity))
                .autoDisposeModule(AutoDisposeModule(requireActivity()))
                .appComponent(getAppComponent())
                .build()
                .inject(this)
    }


    fun onVideoTaskCompleted() {
        SimpleDialogBuilder()
                .title("提示")
                .titleTextColor(R.color.colorPrimary)
                .buttonText("我知道了")
                .content("今日视频任务已完成")
                .build(requireContext())
                .show()
    }

    /**
     * 视频任务未结束，可以观看
     */
    fun onVideoTaskNotCompleted() {
        EventBus.getDefault().post(PlayAdVideoEvent)
    }
}